import Vue from "vue";
import VueRouter from "vue-router";
// import { component } from 'vue/types/umd';

Vue.use(VueRouter);

// 保存原始的 router.push 方法
const originalPush = VueRouter.prototype.push;

// 重写 router.push 方法
VueRouter.prototype.push = function push(location) {
  // 调用原始 push 方法，并捕获可能抛出的错误
  return originalPush.call(this, location).catch((err) => {
    // 如果是重复导航错误，静默处理；否则重新抛出其他错误
    if (err.name !== "NavigationDuplicated") {
      throw err;
    }
  });
};

const routes = [
  // {
  //   path: '/',
  //   name: 'home',
  //   component: HomeView
  // },
  // {
  //   path: '/about',
  //   name: 'about',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  // }
  {
    path: "/",
    name: "index",
    component: () => import("@/views/IndexView.vue"),
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/LoginView.vue"),
  },
  {
    path: "/NewsList",
    name: "newsList",
    component: () => import("@/views/NewsListView.vue"),
  },
  {
    path: "/NewsDetil/:id",
    name: "NewsDetil",
    component: () => import("@/views/NewsDetilView.vue"),
  },
  {
    path: "/UserList",
    name: "userList",
    component: () => import("@/views/UserListView.vue"),
  },
  {
    path: "/Register",
    name: "Register",
    component: () => import("@/views/RegisterView.vue"),
  },
  {
    path: '/CategoryTree',
    name: 'CategoryTree',
    component: () => import('@/views/CategoryTreeView.vue')
  },
  {
    path: "/ProductList",
    name: "ProductList",
    component: () => import("@/views/ProductListView.vue"),
  },
  {
    path: '/AddProduct',
    name: 'AddProduct',
    component: () => import('@/views/AddproductView.vue')
  },
  {
    path: '/userMsg',
    name: 'userMsg',
    component: () => import('@/views/UserMsgView.vue')
  },
  {
    path: '/UserAddress',
    name: 'UserAddress',
    component: () => import('@/views/UserAddressView.vue')
  },

  {
    path: '/ProductOrderList',
    name: 'ProductOrderList',
    component: () => import('@/views/ProductOrderListView.vue')
  },
  {
    path: '/UserOrderList',
    name: 'UserOrderList',
    component: () => import('@/views/UserOrderListView.vue')
  },
  {
    path: '/ShowProduct/:id',
    name: 'ShowProduct',
    component: () => import('@/views/ShowProductView.vue')
  }, 
  {
    path: '/UserFavoriteList',
    name: 'UserFavoriteList',
    component: () => import('@/views/UserFavoriteListView.vue')
  },
  {
    path:'/SearchProduct',
    name:'SearchProduct',
    component:()=>import('@/views/SearchProductView.vue'),
    props: (route) => ({
      // 将路由参数传递给组件 props
      categoryId: route.query.categoryId,
      subCategoryId: route.query.subCategoryId,
      thirdCategoryId: route.query.thirdCategoryId,
    }),
  },
   {
     path:'/BuyCar',
     name:'BuyCar',
     component:()=>import('@/views/BuyCarView.vue'),
   },
   {
     path:'/BuyCarTwo',
     name:'BuyCarTwo',
     component:()=>import('@/views/BuyCarTwoView.vue'),
   },
   {
     path:'/BuyCarThreeView',
     name:'BuyCarThreeView',
     component:()=>import('@/views/BuyCarThreeView.vue'),
   },
   {
     path:'/alipay/AlipayCallbackView',
     name:'AlipayCallbackView',
     component:()=>import('@/views/AlipayCallbackView.vue'),
   },
]



const router = new VueRouter({
  mode: "history",
  routes,
});

export default router;
